﻿<!--
  Odatavalidator ver. 1.0
  Copyright (c) Microsoft Corporation
  All rights reserved.

  Licensed under the Apache License, Version 2.0 (the ""License"");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

  THIS CODE IS PROVIDED ON AN  *AS IS* BASIS, WITHOUT WARRANTIES OR
  CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT
  LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS
  FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.

  See the Apache Version 2.0 License for specific language governing
  permissions and limitations under the License.
-->

<rules>
  <rule id="Error.Core.4614" category="core" target="error" v4specificationsection="19.5.4" version="v4" requirementlevel="may" format="xml">
    <description>The metadata:detail element of metadata:details element MAY contain a metadata:target element.</description>
    <action processor="rng">
      <grammar xmlns="http://relaxng.org/ns/structure/1.0" xmlns:m="http://docs.oasis-open.org/odata/ns/metadata">
        <start>
          <element name="m:error">
            <interleave>
              <zeroOrMore>
                <element name="m:details">
                  <interleave>
                    <oneOrMore>
                      <element name="m:detail">
                        <interleave>
                          <oneOrMore>
                            <element name="m:target">
                              <ref name="anyContent" />
                            </element>
                          </oneOrMore>
                          <zeroOrMore>
                            <ref name="anyNotTargetElement" />
                          </zeroOrMore>
                        </interleave>
                        <ref name="anyContentNotElements" />
                      </element>
                    </oneOrMore>
                    <zeroOrMore>
                      <ref name="anyNotDetailElement" />
                    </zeroOrMore>
                  </interleave>
                  <ref name="anyContentNotElements" />
                </element>
              </zeroOrMore>
              <zeroOrMore>
                <ref name="anyNotDetailsElement" />
              </zeroOrMore>
            </interleave>
            <ref name="anyContentNotElements" />
          </element>
        </start>
        <define name="anyElement">
          <element>
            <anyName />
            <zeroOrMore>
              <choice>
                <attribute>
                  <anyName />
                </attribute>
                <text />
                <ref name="anyElement" />
              </choice>
            </zeroOrMore>
          </element>
        </define>
        <define name="anyContent">
          <zeroOrMore>
            <choice>
              <attribute>
                <anyName />
              </attribute>
              <text />
              <ref name="anyElement" />
            </choice>
          </zeroOrMore>
        </define>
        <define name="anyNotDetailsElement">
          <element>
            <anyName>
              <except>
                <name>m:details</name>
              </except>
            </anyName>
            <zeroOrMore>
              <choice>
                <attribute>
                  <anyName />
                </attribute>
                <text />
                <ref name="anyElement" />
              </choice>
            </zeroOrMore>
          </element>
        </define>
        <define name="anyNotDetailElement">
          <element>
            <anyName>
              <except>
                <name>m:detail</name>
              </except>
            </anyName>
            <zeroOrMore>
              <choice>
                <attribute>
                  <anyName />
                </attribute>
                <text />
                <ref name="anyElement" />
              </choice>
            </zeroOrMore>
          </element>
        </define>
        <define name="anyNotTargetElement">
          <element>
            <anyName>
              <except>
                <name>m:target</name>
              </except>
            </anyName>
            <zeroOrMore>
              <choice>
                <attribute>
                  <anyName />
                </attribute>
                <text />
                <ref name="anyElement" />
              </choice>
            </zeroOrMore>
          </element>
        </define>
        <define name="anyContentNotElements">
          <zeroOrMore>
            <choice>
              <attribute>
                <anyName />
              </attribute>
              <text />
            </choice>
          </zeroOrMore>
        </define>
      </grammar>
    </action>
    <errormessage>The metadata:detail element of metadata:details element MAY contain a metadata:target element.</errormessage>
  </rule>
</rules>